﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using Tesla.DataAccess.DataAccessLogic.Implementations;
using Tesla.Util.Utilities;
using Tesla.Service.DataContracts;
using Tesla.DataAccess.DataAccessLogic.Interfaces;
using Tesla.Business.BusinessLogic.Interfaces;
using System.Transactions;

namespace Tesla.Business.BusinessLogic.Implementations
{
    public class ProjectBL : BaseOperationalBL
    {

        public override int? Create(BaseDC bdc)
        {
            int? success = 0;
            try
            {
                using (TransactionScope transactionScope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 0, int.Parse(ConfigurationSettings.AppSettings["GADNCommandTimeout"]))))
                {
                    BaseOperationalDA daClient = DAFactory.CreateInstance(EntityMapper.PROJECTDA);
                    success = daClient.Create(bdc as BaseDC);
                    transactionScope.Complete();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return success;
        }

        public override int Update(BaseDC bdc)
        {
            int updateResult = 0;

            try
            {
                using (TransactionScope transactionScope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 0, int.Parse(ConfigurationSettings.AppSettings["GADNCommandTimeout"]))))
                {
                    BaseOperationalDA daClient = DAFactory.CreateInstance(EntityMapper.PROJECTDA);
                    updateResult = daClient.Update(bdc as BaseDC);
                    transactionScope.Complete();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return updateResult;
        }

        public override IList<BaseDC> DisplayAll(int gridSize, ref int? totalRecordCount)
        {
            try
            {
                BaseOperationalDA daBase = DAFactory.CreateInstance(EntityMapper.PROJECTDA);
                return daBase.DisplayAll(gridSize, ref totalRecordCount);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public override IList<BaseDC> SearchByName(string name, int gridSize, ref int? totalRecordCount)
        {
            try
            {
                BaseOperationalDA daBase = DAFactory.CreateInstance(EntityMapper.PROJECTDA);
                return daBase.SearchByName(name, gridSize, ref totalRecordCount);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public override IList<BaseDC> Read(int id)
        {

            try
            {
                BaseOperationalDA daProjects= DAFactory.CreateInstance(EntityMapper.PROJECTDA);
                IList<BaseDC> projects = daProjects.Read(id);
                return projects;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

       
       
        public override IList<BaseDC> ReadByRange(int startRecordNo, int endRecordNo, string sortColName, string sortDirection, string searchString)
        {
            try
            {
                BaseOperationalDA daBase = DAFactory.CreateInstance(EntityMapper.PROJECTDA);
                return daBase.ReadByRange(startRecordNo, endRecordNo, sortColName, sortDirection, searchString);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
